package com.mcc.app.group.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.mcc.app.group.domain.GroupTeam;
import com.mcc.app.group.service.IGroupTeamService;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班组
 *
 * @author gxy
 * @date 2021-07-08
 */
@Api(tags = "班组")
@RestController
@RequestMapping("/group/team")
public class GroupTeamController extends BaseController {

    @Autowired
    private IGroupTeamService groupTeamService;

    @ApiOperation("查询班组列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<GroupTeam>> list(GroupTeam groupTeam) {
        List<GroupTeam> list = groupTeamService.selectGroupTeamList(groupTeam);
        return getDataTable(list);
    }

    @ApiOperation("查询班组列表(分页)")
    @ApiOperationSupport(order = 2)
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<GroupTeam>> page(GroupTeam groupTeam) {
        startPage();
        List<GroupTeam> list = groupTeamService.selectGroupTeamList(groupTeam);
        return getDataTable(list);
    }

    @ApiOperation("获取班组详细信息")
    @ApiOperationSupport(order = 3)
    @GetMapping("/get/{teamId}")
    public AjaxResult<GroupTeam> getInfo(@PathVariable("teamId") Long teamId) {
        return AjaxResult.success(groupTeamService.selectGroupTeamById(teamId));
    }

    @ApiOperation("新增班组")
    @ApiOperationSupport(order = 4)
    @Log(title = "班组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GroupTeam groupTeam) {
        return toAjax(groupTeamService.insertGroupTeam(groupTeam));
    }

    @ApiOperation("修改班组")
    @ApiOperationSupport(order = 5)
    @Log(title = "班组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody GroupTeam groupTeam) {
        return toAjax(groupTeamService.updateGroupTeam(groupTeam));
    }

    @ApiOperation("删除班组")
    @ApiOperationSupport(order = 6)
    @Log(title = "班组", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{teamIds}")
    public AjaxResult remove(@PathVariable Long[] teamIds) {
        return toAjax(groupTeamService.deleteGroupTeamByIds(teamIds));
    }
}
